package com.warehouse_management.config;

/**
 * @PACKAGE_NAME: com.warehouse_management.config
 * @NAME: StringRegex
 * @USER: ZhouYongCheng
 * @DATE: 2022/10/4
 * @TIME: 11:32
 * @Description: 字符串每隔三位加’,‘
 */
public class StringRegex {

    public static String subStringToComma(String str, Integer regex) {
        char[] chars = str.toCharArray();
        String temp = "";
        StringBuilder result = new StringBuilder();
        for (int i = 0; i <= chars.length - 1; i++) {
            temp += chars[i];
            if (i == chars.length - 1) {
                result.append(temp);
                break;
            }
            if (temp.length() >= regex) {
                temp += ",";
                result.append(temp);
                temp = "";
            }
        }
        return result.toString();
    }
}
